<template>
  <div class="cart-bottom-bar">
    <div class="left">
      <div class="check-all" :class="{ active: allChecked }" @click="checkAll"></div>
      <span>全选</span>
      <div class="totalPrice">合计:￥{{ totalPrice }}</div>
    </div>
    <div class="right">
      <button class="pay" @click="calcClick">结算({{ goodsCount }})</button>
    </div>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'

  export default {
    name: 'cart-bottom-bar',
    computed: {
      ...mapGetters(['totalPrice', 'allChecked', 'goodsCount'])
    },
    methods: {
      checkAll() {
        if (this.allChecked) {
          this.$store.state.cartList.forEach(item => (item.checked = false))
        } else {
          this.$store.state.cartList.forEach(item => (item.checked = true))
        }
      },
      calcClick() {
        this.$toast.show('结算成功')
      }
    }
  }
</script>

<style lang="less" scoped>
  .cart-bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 30px;
    background-color: #ccc;
  }
  .check-all {
    width: 14px;
    height: 14px;
    border: 3px solid rgb(80, 77, 77);
    border-radius: 8px;
    margin-top: 3px;
  }
  .left {
    display: flex;
    margin-left: 10px;
  }
  .pay {
    width: 100px;
    height: 30px;
    border: none;
    background: indianred;
    color: #fff;
  }
  .totalPrice {
    margin-left: 10px;
  }
  .active {
    background-color: red;
  }
</style>
